YAHOO.namespace("gosearch.Common");


YAHOO.gosearch.Common.asyncRequest = function(method, uri, callback, postData)
{
    // Do the 401 redirect here. Note: this might introduce memory leak because of the usage of closure here. If
    // that's the case, we'll have to put the redirect call to each callback object in our JS code.
    // This is an interceptor that handles 401 status code before aloowing the original "failure" function is invoked.
    var failureFunc = callback['failure'];
    callback.failure = function(response)
    {
        if ( gosearch.security.redirectToLoginPageIf401(response) ){
            // if 401 redirect, do nothing later.
            return;
        }

        // if not 401, do whatever in the original failure function
        if(failureFunc) {
            failureFunc.call(this, response);
        }

    };

    // Force no cache for Ajax request
    callback['cache'] = false;

    return YAHOO.util.Connect.asyncRequest(method, uri, callback, postData);
};
